home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6003 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: mailhub.scitec.com.au!ramsesy
  2. From: ramsesy@rd.scitec.com.au (Ramses Youhana)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: sscanf bug??????
  5. Date: 22 Feb 1996 07:53:16 GMT
  6. Organization: SCITEC LIMITED, Sydney, Australia.
  7. Message-ID: <4gh7dc$i2@mailhub.scitec.com.au>
  8. References: <4fimvo$82s@fnord.dfw.net> <4fqfeo$7mh@umbc9.umbc.edu>
  9. NNTP-Posting-Host: scitec7.scitec.com.au
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Jonas J. Schlein (schlein@umbc.edu) wrote:
  13. > Jerry Jackson <jtmcap@dfw.dfw.net> wrote:
  14. > |> the following is a program compiled using microway ndp c/c++ compiler.
  15.  
  16. > "Compiler produces an executable" != "Your program was correct"
  17.  
  18. > |> #include <stdio.h>
  19. > |> #include <string.h>
  20. > |> 
  21. > |> main()
  22. > |> {
  23. > |>     char str_1[] = "013196";
  24. > |>     char str_2[] = "13196";
  25. > |>     long res_1, res_2;
  26. > |> 
  27. > |>     sscanf(str_1,"%d",&res_1);
  28. > |>     sscanf(str_2,"%d",&res_2);
  29.  
  30. >    <SNIP>
  31.  
  32. > And don't forget:
  33.  
  34. > return (0);
  35.  
  36.  
  37. >    <SNIP>
  38.  
  39. It is also good practice to specify the parameters to a function and its
  40. return values.  This forces an ANSI-C compiler to perform some degree of
  41. parameter and return type checking, hopefully picking up some bugs at
  42. compile time and saving you from lots of headaches during debugging.
  43.  
  44. E.g.
  45.  
  46. int  main (void)
  47.  
  48. instead of
  49.  
  50. main()
  51.  
  52.  
  53.